//
//  FMRegisterViewController.m
//  PsychologyFM
//
//  Created by 杜建虎 on 16/1/16.
//  Copyright © 2016年 ZhangLuDu. All rights reserved.
//

#import "FMRegisterViewController.h"
#import "PKRequestManager.h"
#import "FMZhuCeModel.h"
#import "FMRegister2ViewController.h"
@interface FMRegisterViewController ()<UIAlertViewDelegate>
@property (nonatomic, assign)BOOL isOk;
@property (nonatomic, strong)NSMutableArray *dataArr;
@end

@implementation FMRegisterViewController

- (void)viewDidLoad {
    _isOk = YES;
    _dataArr = [NSMutableArray array];
    [super viewDidLoad];
    

    // Do any additional setup after loading the view.
    self.view.backgroundColor = FMWhite;
    self.navigationItem.title = @"注册";
    
    _inputText = [[UITextField alloc] initWithFrame:CGRectMake(kScreenWidth / 20, 120   , kScreenWidth - kScreenWidth / 10, 20)];
    _inputText.placeholder = @"输入11位有效手机号码";
    [self.view addSubview:_inputText];

    
    _lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 20, _inputText.bottom + 3, kScreenWidth - kScreenWidth / 10 , 1)];
    _lineLabel.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:_lineLabel];
    
    _verifyButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _verifyButton.layer.cornerRadius = 10;
    _verifyButton.frame = CGRectMake(kScreenWidth / 20, _lineLabel.bottom + 20, kScreenWidth - kScreenWidth / 10, 40);
    [_verifyButton addTarget:self action:@selector(verifyButton:) forControlEvents:(UIControlEventTouchUpInside)];
    [_verifyButton setTitle:@"获取验证码" forState:(UIControlStateNormal)];
    _verifyButton.backgroundColor = FMOrange;
    [self.view addSubview:_verifyButton];
    
    _str = _inputText.text;
    
}


- (void)verifyButton:(UIButton *)btn
{
    NSLog(@"2");
    [self requestData];
    
    
}


- (void)requestData
{
    [PKRequestManager requestWithUrlString:[NSString stringWithFormat:@"http://bapi.xinli001.com/users/register_validcode.json/?phone=%@&key=c0d28ec0954084b4426223366293d190",_inputText.text] parDic:nil method:GET finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        FMZhuCeModel *model = [[FMZhuCeModel alloc] init];
        [model setValuesForKeysWithDictionary:dic];
        UIAlertView *alerView = [[UIAlertView alloc] initWithTitle:@"提示" message:model.data delegate:self cancelButtonTitle:@"好的" otherButtonTitles:nil];
        alerView.tag = 1;
        [alerView show];
    } error:^(NSError *error) {
        
    }];
}

#pragma --- UIAlertView点击方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (alertView.tag == 1) {
        if ([alertView.message isEqualToString:@"发送成功"]) {
            FMRegister2ViewController *r2VC = [[FMRegister2ViewController alloc] init];
            r2VC.str = _inputText.text;
            [self.navigationController pushViewController:r2VC animated:NO];

        }
        else{
            
        }
    }
}


@end
